import {defineComponent, getCurrentInstance, ref} from "vue";
import router from "../../../../router/index";

export default defineComponent({
    name: 'pagination',
    components: {},
    props: {
        total: {
            type: Number
        },
        page: {
            type: Number
        },
        pageSize: {
            type: Number
        }
    },
    emits: [],
    setup(props, {emit}) {

        const currentPage = ref(1);


        const handleCurrentChange = (val: number) => {
            currentPage.value = val;
            // 路由替换
            router.replace({
                path: router.path,
                query: {
                    page: val,
                },
            });
            // 传参给父页面
            emit('pagination', val);
        }


        const handleSizeChange = (val: number) => {
            console.log(`每页 ${val} 条`);
        }

        return {
            currentPage,
            handleCurrentChange,
            handleSizeChange
        }
    }
})